package jpao.benchmark;

import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author soa
 */
public class GivenTpsMonitor {

    @Test
    public void whenTenTxOccurInOneSecThenTpsShouldEqualsTen() {
        TpsMonitor tc = new TpsMonitor();
        tc.start();
        for (int i = 0; i < 10; i++) {
            tc.increment();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
        }

        tc.stop();
        assertEquals(10, tc.getStatistics().getElement(0), 0);
    }

    @Test
    public void whenTxOccurThenItShouldProduceValidGoogleChartUrl() {

        TpsMonitor tc = new TpsMonitor();
        tc.start();
        for (int i = 0; i < 50; i++) {
            tc.increment();

            try {
                Thread.sleep((long) (Math.random() * 1000));
            } catch (InterruptedException ex) {
            }
        }
        tc.stop();
        System.out.println(tc.getGoogleChartUrl());
    }
}
